<?php

namespace App\Http\Controllers\Api;

use App\Models\Category;
use App\Models\Product;

class CategoriesController extends Controller
{
    // 分类列表
    public function index()
    {
        $categories = Category::query()->get(['id', 'name', 'image']);

        return $this->success($categories);
    }

    public function show(Category $category)
    {
        return $this->success([
            'category'       => $category,
            'single_product' => Product::query()->with('productTags:id,name,image')->where([
                                'category_id' => $category->id,
                                'type'        => Product::TYPE_SINGLE,
                            ])->get(),
            'box_product'    => Product::query()->where([
                                'category_id' => $category->id,
                                'type'        => Product::TYPE_BOX,
                            ])->get(),
        ]);
    }
}
